package gdut.stream.last;

import gdut.stream.middle.Student;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Optional;

public class MinMaxLamda {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        for (int i = 18; i < 100; i++) {
            Student student = new Student(i, "name" + i);
            students.add(student);
        }
//        获取年龄最大或最小的student
        Optional<Student> max = students.stream()
                .max((stu1, stu2) -> stu1.getAge() - stu2.getAge());
        Optional<Student> min = students.stream()
                .min((stu1, stu2) -> stu1.getAge() - stu2.getAge());
        System.out.println(max.get());
        System.out.println(min.get());
    }
}
